package com.wjs.juc.Future;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

public class CompletableFutureTest2 {
    public static void main(String[] args) {
        CompletableFuture<Integer> task1 = CompletableFuture.supplyAsync(() -> {
            try { TimeUnit.SECONDS.sleep(3); } catch (InterruptedException e) { e.printStackTrace();}
            return 10;
        });
        CompletableFuture<Integer> task2 = CompletableFuture.supplyAsync(() -> {
            try { TimeUnit.SECONDS.sleep(1); } catch (InterruptedException e) { e.printStackTrace();}
            return 20;
        });
        CompletableFuture<Integer> task3 = task1.thenCombine(task2, (r, s) -> {
            System.out.println(r);
            System.out.println(s);
            return r+s;
        });
        System.out.println(task3.join());
    }
}
